cap log close
snapshot erase _all
clear all
estimates drop _all

*===========================*
*	Set Globals				*
*===========================*

	global filenum 21
	global filename "additional_tables"

*===========================*
*	Set Locals				*
*===========================*
	
	#delimit ;
		local m_list 		"12 1 3 4 5 6";
		
		local keep_list1 	"m12_x_y2020 m1_x_y2020 m3_x_y2020 m4_x_y2020 m5_x_y2020 m6_x_y2020";

		local fixed_effect	"statefip"; // can add ind_2digit where appropriate;
		
		local outcomes 		"absent_paid inlf";
	
	#delimit cr
	
*===========================*
*	Load In Analysis File	*
*===========================*
	log using "${log_path}/${filenum}_${filename}.smcl", replace
	
	use "${data_path}/analysis_file.dta" , clear
	
	label var m12_x_y2020 		"December"
	label var m1_x_y2020 		"January"
	label var m3_x_y2020 		"March"
	label var m4_x_y2020 		"April"
	label var m5_x_y2020 		"May"
	label var m6_x_y2020 		"June"

	replace gender_parent = . 	if cdc_levels_m4 != 4		// only want to cut for high april
	
	snapshot save
	
*===================*
* 	DD in Time		*
* 	18/19 vs 20		*
*===================*

	
*===================*
* 	DD in Time		*
* 	18/19 vs 20		*
*===================*


foreach v in `outcomes'{
	
	forvalues t=0/1{
		
		snapshot restore 1
		
		keep if tw_binary_10ly==`t'
		
		#delimit ;

				
		** DYNAMIC DD WITH CONTROLS **;
		
			reghdfe `v' 
					m12-m6 y2020
					m12_x_y2020 - m6_x_y2020
					bachelors age age2 childUnder12
					[w=wtfinl], a(`fixed_effect') vce(cluster cpsidp);
					
			qui sum `v' if asec_year!=2020 [w=wtfinl];
				scalar control_mean = `r(mean)';					
						
			test m12_x_y2020 = m1_x_y2020 = m3_x_y2020 = 0;
				scalar pval=`r(p)';					
							
			est sto dd_tw`t';
			estadd local  	controls 	"YES";
			estadd local 	spec		"DD";
			estadd local 	samp 		"TW `t'";
			estadd scalar 	cmean 		control_mean;
			estadd scalar 	parallel 	pval;	
			
			regsave `keep_list1'
				using "${out_path}/${filenum}_${filename}_`v'.dta",
				addlabel(outcome, "`v'", spec, "DD", sample, "ALL", mu, `=control_mean') replace ;
	
		#delimit cr
		
		forvalues s=0/1{
			snapshot restore 1
			keep if tw_binary_10ly==`t'
			keep if small==`s'
			
			#delimit ;
			** DYNAMIC DD WITH CONTROLS **;
			
				reghdfe `v' 
						m12-m6 y2020
						m12_x_y2020 - m6_x_y2020
						bachelors age age2 childUnder12
						[w=wtfinl], a(`fixed_effect') vce(cluster cpsidp);
							
				qui sum `v' if asec_year!=2020 [w=wtfinl];
					scalar control_mean = `r(mean)';					
							
				test m12_x_y2020 = m1_x_y2020 = m3_x_y2020 = 0;
					scalar pval=`r(p)';					
								
				est sto dd_s`s'_tw`t';
				estadd local  	controls 	"YES";
				estadd local 	spec		"DD";
				estadd local 	samp 		"TW `t'";
				estadd scalar 	cmean 		control_mean;
				estadd scalar 	parallel 	pval;	
				
				regsave `keep_list1'
					using "${out_path}/${filenum}_${filename}_`v'.dta",
					addlabel(outcome, "`v'", spec, "DD", sample, "SMALL `s'", mu, `=control_mean') append ;
		
			#delimit cr			
			
		}
		
	} // end telework loop
	
	#delimit ;
		esttab 	dd_tw0	dd_s1_tw0 dd_s0_tw0
			using "${out_path}/${filenum}_`v'_dd.tex",
			replace	label se star(* 0.1 ** .05 *** 0.01)
			s(cmean spec samp controls parallel N, 
				label("Control Mean" "Model" "Sample" "Controls" "Parallel Trends" "Observations"))
			keep(`keep_list1');	
	
	#delimit cr
	
} // end outcomes loop
log close
